<?php

define('ITEM_TYPE','posts');

class Controller extends PXFController 
{
	public function __construct()
	{
		parent::__construct(); 
	}

	public function index()
	{
	}

	/**
	 * Display items by category.
   */
	public function lists()
	{
		$cat_id = PXFRequest::reqGetOrDefault('cat',PXFConfig::DEFAULT_CATEGORY); 
		
		$mod_categories = PXFModel::getModel('category');
		$category = $mod_categories->find($cat_id);

		$params = array();
		$params['condition'] = new PXFCondition('visibility',PXFConfig::VISIBILITY_PUBLIC);
		$params['condition']->add(PXFCondition::opAND('typed',ITEM_TYPE));

		$count = $category->item->count($params);
		$paginator = new PXFPaginator($count,array());
	  $params['limit'] = array($paginator->from,$paginator->disp);
		$params['order'] = array('item_order');
		$items = $category->item($params);

		PXFConfig::$site['page_title'] = $category->title;
		$this->tpl->assign('site',PXFConfig::$site);
		$this->tpl->assign('items',$items);
		$this->tpl->display(sprintf('%s.%s.tpl',ITEM_TYPE,PXFInstance::$action));
	}

	/**
	 * Display one item by category.
   */
	public function view()
	{
		$id = PXFRequest::reqGetOr404('id'); 
		$mod_items = PXFModel::getModel('item');
		$item = $mod_items->find($id);
		PXFRequest::notNullOr404($item);
		PXFConfig::$site['page_title'] = $item->title;
		$this->tpl->assign('site',PXFConfig::$site);
		$this->tpl->assign('item',$item);
		$this->tpl->display(sprintf('%s.%s.tpl',ITEM_TYPE,PXFInstance::$action));
	}
}

?>

